package cn.com.nes.site.action.inventory;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.inventory.OrderOutService;

@Controller("orderout")
@RequestMapping("/orderout")
public class OrderOutAction {
	@Resource
	private OrderOutService service;

	//查询入库申请单列表
    @RequestMapping(method = RequestMethod.POST, value = "/getApplyList")
    public @ResponseBody
    PageData getApplyList(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getApplyList(req) ;
        return res;
    }
    
    //生成入库申请单ID
    @RequestMapping(method = RequestMethod.POST, value = "/generateApplyId")
    public @ResponseBody
    PageData generateApplyId(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.generateApplyId(req) ;
        return res;
    }
    
    //保存入库申请单信息
    @RequestMapping(method = RequestMethod.POST, value = "/saveApplyInfo")
    public @ResponseBody
    PageData saveApplyInfo(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.saveApplyInfo(req) ;
        return res;
    }
    
    //获取入库申请单详情
    @RequestMapping(method = RequestMethod.POST, value = "/getApplyDetail")
    public @ResponseBody
    PageData getApplyDetail(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getApplyDetail(req) ;
        return res;
    }
    
  //修改申请单货品信息
    @RequestMapping(method = RequestMethod.POST, value = "/updateApplyGoodsInfo")
    public @ResponseBody
    PageData updateApplyGoodsInfo(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.updateApplyGoodsInfo(req) ;
        return res;
    }
    
    //删除入库申请单明细
    @RequestMapping(method = RequestMethod.POST, value = "/delApplyGoods")
    public @ResponseBody
    PageData delApplyGoods(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delApplyGoods(req) ;
        return res;
    }
    
    //删除入库申请单
    @RequestMapping(method = RequestMethod.POST, value = "/delApply")
    public @ResponseBody
    PageData delApply(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.delApply(req) ;
        return res;
    }
    
    //提交入库单申请
    @RequestMapping(method = RequestMethod.POST, value = "/submitOrderOutApply")
    public @ResponseBody
    PageData submitOrderOutApply(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.submitOrderOutApply(req) ;
        return res;
    }
    
    //提交入库单审核
    @RequestMapping(method = RequestMethod.POST, value = "/submitOrderOutAudit")
    public @ResponseBody
    PageData submitOrderOutAudit(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.submitOrderOutAudit(req) ;
        return res;
    }
    

    //-以下是入库单操作---------------------------
    
    //生成入库单ID
    @RequestMapping(method = RequestMethod.POST, value = "/generateOrderId")
    public @ResponseBody
    PageData generateOrderId(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.generateOrderId(req) ;
        return res;
    }
    
    //获取入库登记列表
    @RequestMapping(method = RequestMethod.POST, value = "/getOrderOutList")
    public @ResponseBody
    PageData getOrderOutList(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getOrderOutList(req) ;
        return res;
    }
    
    //获取申请单商品列表
    @RequestMapping(method = RequestMethod.POST, value = "/getApplyGoodsList")
    public @ResponseBody
    PageData getApplyGoodsList(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getApplyGoodsList(req) ;
        return res;
    }
    
    //保存入库确认单
    @RequestMapping(method = RequestMethod.POST, value = "/submitOrderOutConfirm")
    public @ResponseBody
    PageData submitOrderOutConfirm(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.submitOrderOutConfirm(req) ;
        return res;
    }
    
    
    //获取入库单详情
    @RequestMapping(method = RequestMethod.POST, value = "/getOrderOutDetail")
    public @ResponseBody
    PageData getOrderOutDetail(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.getOrderOutDetail(req) ;
        return res;
    }
    
    //出库单冲账
    @RequestMapping(method = RequestMethod.POST, value = "/orderOutReturn")
    public @ResponseBody
    PageData orderOutReturn(HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws Exception {
        DataRes req_Status = DBUtils.setRemoteVisit(request, response,true);
        PageData res = new PageData() ;
        if (req_Status.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(req_Status.getRetCode()) ;
            res.setRetMessage(req_Status.getRetMessage());
            return res;
        }
        DataReq req = req_Status.getReq() ;
        res = service.orderOutReturn(req) ;
        return res;
    }
}
